// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user';
Vue.use(Vuex);//vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state:{//存放状态
		CartList:uni.getStorageSync('cart')||[]
	},
	mutations:{
		updateCartList(state,CartList){
			state.CartList=CartList
			uni.setStorageSync('cart',CartList)
		}
	},
	getters:{
		checkList(state){
			return state.CartList.filter(item=>item.goods_checked)
		},
		checkTotal(_,getters){
     return getters.checkList.reduce((sum,item)=>sum+item.goods_number,0)
		},
		checkPrice(_,getters){
			return getters.checkList.reduce((sum,item)=>sum+item.goods_number*item.goods_price,0)
		 }
	},
	modules:{
		user
	}
})
export default store